const HttpClass = require('./Class/Http')
const storageModule = require('@/storage/index')
module.exports = new HttpClass({
  httpMethod: wx.uploadFile,
  baseURL: '',
  header: {
    'content-type': 'application/x-www-form-urlencoded'
  },
  timeout: 1000 * 30,
  interceptors: {
    request(config) {
    //   console.log(config)
      // 添加请求头 token
      config.header['token'] = storageModule.getToken()
      return config
    },
    response(res, error) {
      if (res) {
        const transformRes = Object.assign({}, res)
        // 原生res.data 为 JSONString
        if (transformRes.data && typeof transformRes.data === 'string') {
          transformRes.data = JSON.parse(transformRes.data)
        }
        return transformRes
      } else {
        return error
      }
    }
  }
})
